import {useDimensionality} from './hooks'
import {getLabelById} from '@/utils/common'

export const useStoreTableConfig = (props) => {
  const {brandList}=useDimensionality()
  const _salesStateList = [{
    label: '正常',
    value:1,
  },{
    label: '停售',
    value:2,
  }]
  const _mallInfoPutList = [
    {
      label: '允许',
      value:1,
    },{
      label: '不允许',
      value:2,
    }
  ]
  const productForm = ref([
    {
      type: 'input',
      prop: "fuzzyValue",
      placeholder: "产品名称/编号/助记码",
      label: "",
      model: "",
    },
    {
      type: "select",
      placeholder: "经营品牌",
      multiple: true,
      filterable: true,
      label: '',
      prop: 'businessBrandIdList',
      data: brandList,
      model: [],
    },
    {
      type: 'select',
      prop: "salesState",
      placeholder: "销售状态",
      label: "",
      data:_salesStateList,
      model: "",
    },
    {
      type: 'select',
      prop: "mallInfoPut",
      placeholder: "允许上架商城",
      label: "",
      data:_mallInfoPutList,
      model: "",
    }
  ])
  const productTableConfig = ref([
    {
      label: '产品编号',
      prop: 'code',
      type:'slot',
      slotName:'product'
    },
    {
      label: '产品名称',
      prop: 'name',
      width: 310,
      textOverflow:true,
      type:'slot',
      slotName:'productName'
    },
    {
      label: '经营品牌',
      prop: 'brandId',
      format:(value)=>{
        if(!value) return '-'
        const ids = value.split(',')
        return getLabelById(ids, brandList) || '-'
      }
    },
    {
      label: '零售价',
      prop: 'retailPrice',
    },
    {
      label: '批发价',
      prop: 'wholesaleInfoPrice',
    },
    {
      label: '销售状态',
      prop: 'salesState',
      format:(value)=>{
        return _salesStateList.find(item=>item.value===value)?.label || '-';
      }
    },
    {
      label: '允许上架商城',
      width: 150,
      prop: 'mallInfoPut',
      format:(value)=>{
        return _mallInfoPutList.find(item=>item.value===value)?.label || '-';
      }
    },
  ])
  const projectForm = ref([
    ...productForm.value,
  ])
  projectForm.value[0] = {
    type: 'input',
    prop: "fuzzyValue",
    placeholder: "项目名称/编号/助记码",
    label: "",
    model: "",
  }
  const projectTableConfig = ref([
    {
      label: '项目编号',
      prop: 'code',
      type:'slot',
      slotName:'product'
    },
    {
      label: '项目名称',
      prop: 'name',
      width: 310,
      textOverflow:true,
      type:'slot',
      slotName:'productName'
    },
    {
      label: '经营品牌',
      prop: 'brandId',
      format:(value)=>{
        if(!value) return '-'
        const ids = value.split(',')
        return getLabelById(ids, brandList) || '-'
      }
    },
    {
      label: '零售价',
      prop: 'retailPrice',
    },
    {
      label: '关联耗材',
      prop: 'existsDisposables',
      format:(value)=>{
        if(!value) return '-'
        return value ? '是' : '否'
      }
    },
    {
      label: '门店销售状态',
      prop: 'salesState',
      format:(value)=>{
        return _salesStateList.find(item=>item.value===value)?.label || '-';
      }
    },
    {
      label: '允许上架商城',
      width: 150,
      prop: 'mallInfoPut',
      format:(value)=>{
        return _mallInfoPutList.find(item=>item.value===value)?.label || '-';
      }
    },
  ])
  const setMealForm = ref([
    ...productForm.value,
  ])
  setMealForm.value[0] = {
    type: 'input',
    prop: "fuzzyValue",
    placeholder: "套餐名称/编号/助记码",
    label: "",
    model: "",
  }
  const setMealTableConfig = ref([
    {
      label: '套餐编号',
      prop: 'code',
      type:'slot',
      slotName:'product',
      width:160,
    },
    {
      label: '套餐名称',
      prop: 'name',
      width: 300,
      textOverflow:true,
      type:'slot',
      slotName:'productName'
    },
    {
      label: '经营品牌',
      prop: 'brandId',
      format:(value)=>{
        if(!value) return '-'
        const ids = value.split(',')
        return getLabelById(ids, brandList) || '-'
      }
    },
    {
      label: '项目种类',
      prop: 'projectNum',
    },
    {
      label: '产品种类',
      prop: 'productNum',
    },
    {
      label: '零售价',
      prop: 'retailPrice',
    },
    {
      label: '门店销售状态',
      prop: 'salesState',
      format:(value)=>{
        return _salesStateList.find(item=>item.value===value)?.label || '-';
      }
    },
    {
      label: '允许上架商城',
      width: 150,
      prop: 'mallInfoPut',
      format:(value)=>{
        return _mallInfoPutList.find(item=>item.value===value)?.label || '-';
      }
    },
  ])
  const suppliesForm = ref([
    {
      type: 'input',
      prop: "name",
      placeholder: "物资名称/编号/助记码",
      label: "",
      model: "",
    },
    {
      type: "select",
      placeholder: "经营品牌",
      multiple: true,
      filterable: true,
      label: '',
      prop: 'businessBrandIdList',
      data: brandList,
      model: [],
    },
  ])
  const suppliesTableConfig = ref([
    {
      label: '物资编号',
      prop: 'code',
      type:'slot',
      slotName:'product'
    },
    {
      label: '物资名称',
      prop: 'name',
      width: 310,
      textOverflow:true,
      type:'slot',
      slotName:'productName'
    },
    {
      label: '商品类别',
      prop: 'category',
    },
    {
      label: '经营品牌',
      prop: 'brandId',
      format:(value)=>{
        if(!value) return '-'
        const ids = value.split(',')
        return getLabelById(ids, brandList) || '-'
      }
    },
    {
      label: '批发价',
      prop: 'wholesaleInfoPrice',
    },
  ])
  const treatmentCourseForm =ref([
    ...productForm.value
  ])
  treatmentCourseForm.value[0] = {
    type: 'input',
    prop: "fuzzyValue",
    placeholder: "疗程名称/编号/助记码",
    label: "",
    model: "",
  }
  const treatmentCourseTableConfig = ref([
    {
      label: '疗程编号',
      prop: 'code',
      type:'slot',
      slotName:'product'
    },
    {
      label: '疗程名称',
      prop: 'name',
      width: 310,
      textOverflow:true,
      type:'slot',
      slotName:'productName'
    },
    {
      label: '经营品牌',
      prop: 'brandId',
      format:(value)=>{
        if(!value) return '-'
        const ids = value.split(',')
        return getLabelById(ids, brandList) || '-'
      }
    },
    {
      label: '项目种类',
      prop: 'projectNum',
    },
    {
      label: '疗程次数',
      prop: 'courseTimes',
    },
    {
      label: '零售价',
      prop: 'retailPrice',
    },
    {
      label: '销售状态',
      prop: 'salesState',
      format:(value)=>{
        return _salesStateList.find(item=>item.value===value)?.label || '-';
      }
    },
  ])
  return {
    productForm,
    productTableConfig,
    projectForm,
    projectTableConfig,
    setMealForm,
    setMealTableConfig,
    suppliesForm,
    suppliesTableConfig,
    treatmentCourseForm,
    treatmentCourseTableConfig
  }
}

export const useStoreHeaderConfig = ()=>{
  // 产品类型（1-产品，2-项目，3-套餐,4-物资, 7-疗程）
  const headerConfig = ref([
    {
      leftName: '产品种类',
      leftNum: 0,
      rightName: '商城',
      classify:1,
      rightNum: 0,
      leftColor: '#3480FF',
      rightColor: '#18BF5B',
      leftBgColor: '#EBF2FF',
      rightBgColor: '#D6E6FF'
    },
    {
      leftName: '项目种类',
      leftNum: 0,
      rightName: '商城',
      classify:2,
      rightNum: 0,
      leftColor: '#66D592',
      rightColor: '#18BF5B',
      leftBgColor: '#E8F9EF',
      rightBgColor: '#D1F2DE'
    },
    {
      classify:3,
      leftName: '套餐种类',
      leftNum: 0,
      rightName: '商城',
      rightNum: 0,
      leftColor: '#0C268C',
      rightColor: '#18BF5B',
      leftBgColor: '#F0F2F8',
      rightBgColor: '#DBDFEE'
    }
  ])
  const suppliesConfig=ref([
    {
      classify:7,
      bgColor:'#FFF7E5',
      name:'疗程种类',
      num:0,
      color:'#FF6B00'
    },
    {
      classify:4,
      bgColor:'#FFF0E5',
      name:'物资种类',
      num:0,
      color:'#FF6B00'
    }
  ])
  return {
    headerConfig,
    suppliesConfig
  }
}